home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvg110a.zip / T6DEMSRC.ZIP / STYX.PAS next >
Pascal/Delphi Source File  |  1993-02-21  |  4KB  |  166 lines

  1. {************************************************}
  2. { STYX DEMO FOR TVDEMO, using TVGRAPH            }
  3. {************************************************}
  4.  
  5. unit Styx;
  6.  
  7. {$F+,O-,X+,S-,D+,L+}
  8.  
  9. { Graphics Styx demo }
  10.  
  11. interface
  12.  
  13. uses TVGraph, TvgDefs, TvGWhiz, DemoCmds, Objects, App, Views, Drivers, Crt;
  14. const
  15.  cmStyx=1100;
  16. type
  17.   XYCord = record
  18.    XA,YA,XB,YB:integer;
  19.   end;
  20.   PStyx = ^TStyx;
  21.   TStyx = object(TVGView)
  22.     CurrentStick:byte;
  23.     Velocity:XYCord;
  24.     StyxLocations:Array[0..15] of XYCord;
  25.     constructor Init(Var Bounds:Trect);
  26.     procedure Prod; virtual;
  27.     procedure GraphDraw; virtual;
  28.   end;
  29.  
  30.   PStyxDemo = ^TStyxDemo;
  31.   TStyxDemo = object(TVGWindow)
  32.     constructor Init;
  33.   end;
  34.  
  35. const
  36.  
  37.   AsciiTableCommandBase: Word = 910;
  38.  
  39.   RStyx: TStreamRec = (
  40.      ObjType: 10090;
  41.      VmtLink: Ofs(TypeOf(TStyx)^);
  42.      Load:    @TStyx.Load;
  43.      Store:   @TStyx.Store
  44.   );
  45.   RStyxDemo: TStreamRec = (
  46.      ObjType: 10091;
  47.      VmtLink: Ofs(TypeOf(TStyxDemo)^);
  48.      Load:    @TStyxDemo.Load;
  49.      Store:   @TStyxDemo.Store
  50.   );
  51.  
  52. procedure RegisterStyx;
  53.  
  54. implementation
  55.  
  56. constructor TStyx.Init(Var Bounds:Trect);
  57. var
  58.  R:GRect;
  59. begin
  60.  TVGView.Init(Bounds);
  61.  CurrentStick:=0;
  62.  fillchar(StyxLocations,Sizeof(StyxLocations),#0);
  63.  UseGraphId(GraphWindowId);
  64.  GetGraphBounds(R);
  65.  with Styxlocations[0] do
  66.  with R do
  67.  begin
  68.     XA:=(B.X-A.X) div 2;
  69.     YA:=(B.Y-A.Y) div 2;
  70.     XB:=(B.X-A.X) div 3;
  71.     YB:=(B.Y-A.Y) div 3;
  72.  end;
  73.  with Velocity do
  74.  begin
  75.     XA:=random(4)+1;if XA>2 then XA:=2-XA;
  76.     XA:=XA*16;
  77.     YA:=random(4)+1;if YA>2 then YA:=2-YA;
  78.     YA:=YA*16;
  79.     XB:=random(4)+1;if XB>2 then XB:=2-XB;
  80.     XB:=XB*16;
  81.     YB:=random(4)+1;if YB>2 then YB:=2-YB;
  82.     YB:=YB*16;
  83.  end;
  84. end;
  85.  
  86. procedure TStyx.GraphDraw;
  87. const
  88.  StyxColor:array[0..15] of byte =(15,11,11,9,9,9,9,1,1,1,1,1,1,1,1,0);
  89. var
  90.  R:GRect;
  91.  Count:byte;
  92.  Actual:byte;
  93. begin
  94.  UseGraphId(GraphWindowId);
  95.  GetGraphBounds(R);
  96.  for count:=0 to 15 do
  97.  begin
  98.   Actual:=(16-Count+CurrentStick) mod 16;
  99.   with Styxlocations[Count] do
  100.      DrawLine(R.A.X+XA,R.A.Y+YA,R.A.X+XB,R.A.Y+YB,StyxColor[Actual]);
  101.  end;
  102. end;
  103.  
  104. procedure TStyx.Prod;
  105. var
  106.  Count:byte;
  107.  R:GRect;
  108.  LS:byte;
  109.  XMax,YMax:word;
  110. begin
  111.  UseGraphId(GraphWindowId);
  112.  GetGraphBounds(R);
  113.  LS:=CurrentStick;
  114.  CurrentStick:=(CurrentStick+1) mod 16;
  115.  XMax:=R.B.X-R.A.X-1;
  116.  YMax:=R.B.Y-R.A.Y-1;
  117.  with Styxlocations[CurrentStick] do
  118.    with R do
  119.    begin
  120.       XA:=Styxlocations[LS].XA+Velocity.XA;
  121.       if (XA<0) or (XA>XMax) then
  122.       begin
  123.        Velocity.XA:=-Velocity.XA;
  124.        if XA<0 then XA:=0 else XA:=XMax
  125.       end;
  126.       XB:=Styxlocations[LS].XB+Velocity.XB;
  127.       if (XB<0) or (XB>XMax) then
  128.       begin
  129.        Velocity.XB:=-Velocity.XB;
  130.        if XB<0 then XB:=0 else XB:=XMax
  131.       end;
  132.       YA:=Styxlocations[LS].YA+Velocity.YA;
  133.       if (YA<0) or (YA>YMax) then
  134.       begin
  135.        Velocity.YA:=-Velocity.YA;
  136.        if YA<0 then YA:=0 else YA:=YMax
  137.       end;
  138.       YB:=Styxlocations[LS].YB+Velocity.YB;
  139.       if (YB<0) or (YB>YMax) then
  140.       begin
  141.        Velocity.YB:=-Velocity.YB;
  142.        if YB<0 then YB:=0 else YB:=YMax
  143.       end;
  144.    end;
  145.  GraphDraw;
  146. end;
  147.  
  148. constructor TStyxDemo.Init;
  149. var
  150.   R: TRect;
  151. begin
  152.   R.Assign(0, 0, 34, 12);
  153.   TVGWindow.Init(R, 'S T Y X', wnNoNumber);
  154.   GetExtent(R);
  155.   R.Grow(-1,-1);
  156.   Insert(New(PStyx, Init(R)));
  157. end;
  158.  
  159. procedure RegisterStyx;
  160. begin
  161.   RegisterType(RStyx);
  162.   RegisterType(RStyxDemo);
  163. end;
  164.  
  165. end.
  166.